package com.lightsaber.trade.core.dao.account;

import java.util.List;

import org.springframework.stereotype.Component;

import com.lightsaber.trade.core.dao.BaseDao;
import com.lightsaber.trade.core.entity.account.Authority;

/**
 * 授权对象的泛型DAO.
 * 
 * @author LiuJian
 */
@Component
public class AuthorityDao extends BaseDao<Authority, String> {

    @SuppressWarnings("unchecked")
    public List<Authority> getAuthorityWithInterceptUrl() {

        isNotNull("interceptUrl");

        return list();
    }

    @SuppressWarnings("unchecked")
    public List<Authority> findByUserAndRole(String userName, String roleCode) {
        String hql = "select ra.authority from UserRole ur, RoleAuthority ra where "
                + "ur.user.loginId=:userName and ur.role.name=:roleName and ur.role=ra.role";

        return createQuery(hql).setString("userName", userName).setString("roleName", roleCode)
                .list();
    }
}
